/**
 * 1.version:5.0 data:2024/3/26
 * 2.本文件可实现GPIO中断、UART配置、CAN配置与TIM中断回调函数自由绑定
 */

#ifndef INTERRUPTMANAGER
#define INTERRUPTMANAGER

#ifdef __cplusplus
extern "C "
{
#endif

#include "main.h"
#include <stdio.h>

//----------------------------------------------------------------------------------------------------------------
// 如果启用GPIO中断功能
#ifdef HAL_GPIO_MODULE_ENABLED
    extern void attachinterrupt_gpio(uint16_t gpio_pin, void (*gpio_callback)(void));
#endif /* HAL_GPIO_MODULE_ENABLED */

//-----------------------------------------------------------------------------------------------------------------
// 如果启用UART中断或者DMA功能
#ifdef HAL_UART_MODULE_ENABLED
#include "usart.h"
#define PRINT_UART huart1
    extern void attachinterrupt_uart(UART_HandleTypeDef *huart, uint8_t buf_size, void (*uart_callback)(uint8_t *pdata, uint8_t size));
    extern void attachinterrupt_uart_dma(UART_HandleTypeDef *huart, uint8_t *pbuf, uint8_t buf_size, void (*uart_callback)(void));
#endif /* HAL_UART_MODULE_ENABLED */

//-----------------------------------------------------------------------------------------------------------------
// 如果启用CAN功能
#ifdef HAL_CAN_MODULE_ENABLED
#include "can.h"
    extern void can_transmit(CAN_HandleTypeDef *hcan, uint16_t id, uint8_t *buf);
    extern void can_filterinit(CAN_HandleTypeDef *hcan);
    extern void attachinterrupt_can(CAN_HandleTypeDef *hcan, void (*can_callback)(CAN_RxHeaderTypeDef *pheader, uint8_t *pdata));
#endif /* HAL_CAN_MODULE_ENABLED */

//-----------------------------------------------------------------------------------------------------------------
// 如果启用TIM base功能
#ifdef HAL_TIM_MODULE_ENABLED
#include "tim.h"
    extern void attachInterrupt_tim(TIM_HandleTypeDef *htim, void (*tim_callback)(void));
    extern void tim_period_elapsed_callback(TIM_HandleTypeDef *htim);
#endif /* HAL_TIM_MODULE_ENABLED */

#ifdef __cplusplus
}
#endif

#endif
